package com.recipedb.sprint.controller;

import com.recipedb.sprint.service.PointsRewardsService;
import com.recipedb.sprint.service.PointRecordsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/points")
public class PointRecordsController {

    private final PointsRewardsService pointsRewardsService;
    private final PointRecordsService pointRecordsService;

    public PointRecordsController(PointsRewardsService pointsRewardsService,
                                  PointRecordsService pointRecordsService) {
        this.pointsRewardsService = pointsRewardsService;
        this.pointRecordsService = pointRecordsService;
    }

    /**
     * 查询单条兑换/积分记录详情
     */
    @GetMapping("/record/{recordId}")
    public ResponseEntity<Map<String, Object>> getRecordDetail(@PathVariable Long recordId) {
        try {
            Map<String, Object> data = pointRecordsService.getRecordDetail(recordId);

            Map<String, Object> response = new HashMap<>();
            response.put("code", 200);
            response.put("data", data);
            return ResponseEntity.ok(response);

        } catch (Exception e) {
            Map<String, Object> error = new HashMap<>();
            error.put("code", 500);
            error.put("msg", e.getMessage());
            return ResponseEntity.badRequest().body(error);
        }
    }
}
